import React from 'react';

interface GlassButtonProps {
  children: React.ReactNode;
  className?: string;
  /** 按钮类型 */
  variant?: 'default' | 'primary' | 'danger';
  /** 按钮大小 */
  size?: 'sm' | 'md' | 'lg';
  /** 是否禁用 */
  disabled?: boolean;
  /** 是否加载中 */
  loading?: boolean;
  /** 点击事件 */
  onClick?: () => void;
  /** 按钮类型 */
  type?: 'button' | 'submit' | 'reset';
}

/**
 * 毛玻璃按钮组件
 * 提供平滑的过渡动画效果
 * Requirements: 8.3
 */
export const GlassButton: React.FC<GlassButtonProps> = ({
  children,
  className = '',
  variant = 'default',
  size = 'md',
  disabled = false,
  loading = false,
  onClick,
  type = 'button',
}) => {
  const baseClasses = `
    backdrop-blur-md border rounded-lg font-medium 
    transition-all duration-300 ease-out
    inline-flex items-center justify-center
    transform hover:scale-105 active:scale-95
  `;
  
  const variantClasses = {
    default: 'bg-white/80 border-emerald-200 text-gray-700 hover:bg-emerald-50 hover:border-emerald-300 hover:shadow-emerald-200/50 hover:shadow-lg',
    primary: 'bg-emerald-500 border-emerald-400 text-white hover:bg-emerald-600 hover:border-emerald-500 hover:shadow-emerald-500/30 hover:shadow-lg',
    danger: 'bg-red-500 border-red-400 text-white hover:bg-red-600 hover:border-red-500 hover:shadow-red-500/20 hover:shadow-lg',
  };
  
  const sizeClasses = {
    sm: 'px-3 py-1.5 text-sm',
    md: 'px-4 py-2 text-base',
    lg: 'px-6 py-3 text-lg',
  };
  
  const disabledClasses = disabled || loading 
    ? 'opacity-50 cursor-not-allowed hover:scale-100 active:scale-100' 
    : 'cursor-pointer';
  
  return (
    <button
      type={type}
      className={`${baseClasses} ${variantClasses[variant]} ${sizeClasses[size]} ${disabledClasses} ${className}`}
      onClick={onClick}
      disabled={disabled || loading}
    >
      {loading && (
        <svg className="animate-spin -ml-1 mr-2 h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
          <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
          <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
        </svg>
      )}
      {children}
    </button>
  );
};

export default GlassButton;
